package com.pvdnc.systemdebugger.ipcmanager;

import android.app.Notification;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import com.pvdnc.systemdebugger.compacter.IAuth;
import com.pvdnc.systemdebugger.compacter.PBServiceManager;
import com.pvdnc.systemdebugger.compacter.PBServiceManagerProxy;
import com.pvdnc.systemdebugger.compacter.utils.AppContext;

import java.util.Arrays;

public class KAService extends Service {
    private static final String TAG="KAService";

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    private static boolean SERVICE_STARTED=false;

    public static void startSelf(){
        if(SERVICE_STARTED)
            return;
        Context appContext=AppContext.getAppContext();
        if(appContext==null){
            Log.e(TAG,"fail to start service because appContext is null");
            return;
        }
        appContext.startService(new Intent(appContext,KAService.class));
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        SERVICE_STARTED=true;
        Log.d(TAG, "start to register PBServiceManager");
        PBServiceManager.registerSelf();
        Log.d(TAG, "list of all services:\n" + Arrays.toString(PBServiceManager.listServices()));
        AppOps.setUidMode();
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        SERVICE_STARTED=false;
    }
}
